/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.tmq.diancan.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tmq.diancan.entity.DiancanNotice;
import com.tmq.diancan.service.IDiancanNoticeService;
import com.tmq.diancan.vo.DiancanNoticeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 通知公告 控制器
 *
 * @author tangmqb
 * @since 2020-01-04
 */
@RestController
@AllArgsConstructor
@RequestMapping("/diancannotice")
@Api(value = "通知公告", tags = "通知公告接口")
public class DiancanNoticeController {

	private IDiancanNoticeService diancanNoticeService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入diancanNotice")
	public R<DiancanNotice> detail(DiancanNotice diancanNotice) {
		DiancanNotice detail = diancanNoticeService.getOne(Condition.getQueryWrapper(diancanNotice));
		return R.data(detail);
	}

	/**
	 * 分页 通知公告
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入diancanNotice")
	public R<IPage<DiancanNotice>> list(DiancanNotice diancanNotice, Query query) {
		IPage<DiancanNotice> pages = diancanNoticeService.page(Condition.getPage(query), Condition.getQueryWrapper(diancanNotice));
		return R.data(pages);
	}

	/**
	 * 自定义分页 通知公告
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入diancanNotice")
	public R<IPage<DiancanNoticeVO>> page(DiancanNoticeVO diancanNotice, Query query) {
		IPage<DiancanNoticeVO> pages = diancanNoticeService.selectDiancanNoticePage(Condition.getPage(query), diancanNotice);
		return R.data(pages);
	}

	/**
	 * 新增 通知公告
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入diancanNotice")
	public R save(@Valid @RequestBody DiancanNotice diancanNotice) {
		return R.status(diancanNoticeService.save(diancanNotice));
	}

	/**
	 * 修改 通知公告
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入diancanNotice")
	public R update(@Valid @RequestBody DiancanNotice diancanNotice) {
		return R.status(diancanNoticeService.updateById(diancanNotice));
	}

	/**
	 * 新增或修改 通知公告
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入diancanNotice")
	public R submit(@Valid @RequestBody DiancanNotice diancanNotice) {
		return R.status(diancanNoticeService.saveOrUpdate(diancanNotice));
	}

	
	/**
	 * 删除 通知公告
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(diancanNoticeService.removeByIds(Func.toIntList(ids)));
	}

	
}
